<?php
/*
 * @ControllerAnnotation(title="客户管理控制台")
 */

namespace app\crm\controller;

use app\common\controller\CrmController;

class Dashboard extends CrmController
{
    /**
     * @NodeAnotation(title="查看")
     */    
    public function index()
    {
        //当天开始时间
        $start_time = strtotime(date("Y-m-d",time()));
        //当天结束之间
        $end_time = $start_time + 60*60*24;
        $filter_w['owner_user_id'] = session('admin.id');
        $customerModel = model('\app\crm\model\CrmCustomer');
        $cluesModel = model('\app\crm\model\CrmClues');
        //需要联系客户
        $communicate = $customerModel->where('next_time','between',[1,$end_time])
                    ->where($filter_w)
                    ->count();

        //需要联系的线索
        $clues_num = $cluesModel->where('next_time','between',[1,$end_time])
                    ->where($filter_w)
                    ->count();
        //将要过期的用户
        $lose_num=count(\app\common\service\CustomerService::getLose(session('admin.id')));
        // 商机
        $businessModel = model('\app\crm\model\CrmBusiness');
        $business = $businessModel->where('next_time','between',[1,$end_time])
                    ->where($filter_w)
                    ->count();
        // 到期订单
        $orderModel = model('\app\crm\model\CrmOrder');
        $filter_w['check_status'] = 2;
        //快过期和过期订单
        $order_expire = $orderModel->where('end_time','between',[1,$end_time+(30*86400)])
                        ->where('expire_handle',0)
                        ->where($filter_w)
                        ->count();
        //待回款订单
        $order_return = $orderModel->where("money","exp",">return_money")
                ->where($filter_w)
                ->count();  
      
        $this->assign([
            'communicate' => $communicate,
            'lose_num' => $lose_num,
            'business' => $business,
            'order_expire' => $order_expire,
            'order_return' => $order_return,
            'clues_num' => $clues_num
        ]);
        return $this->fetch();
    }

    

}